home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 966 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Array of pointers to a tree structure ?
  5. Date: 10 Jan 1996 15:22:04 GMT
  6. Organization: Computer People Inc.
  7. Distribution: world
  8. Message-ID: <ALUN.CHAMPION.96Jan10102204@g7240065.bridge.bst.bls.com>
  9. References: <4d067t$9lc@hermes.fundp.ac.be>
  10.     <nxRvQDA1468wEw$$@harden.demon.co.uk>
  11. NNTP-Posting-Host: bstfirewall.bst.bls.com
  12. In-reply-to: Mark Harden's message of Wed, 10 Jan 1996 12:16:53 +0000
  13.  
  14. In article <nxRvQDA1468wEw$$@harden.demon.co.uk> Mark Harden <mark@harden.demon.co.uk> writes:
  15. : In article <4d067t$9lc@hermes.fundp.ac.be>, Francisco Melo Ledermann
  16. : <fmelo@biq.fundp.ac.be> writes
  17. :> Hi Colleagues, I have been learning C language just from one month ago 
  18. :> and I don't know too much about this language. I have a problem with the 
  19. :> assignment of pointers in an array of pointers with a specifical defined 
  20. :> structure. For example:
  21.  
  22. :> /* BOXES STRUCTURE FOR THE CONSTRUCTION OF A TREE */
  23.  
  24. :> struct boxes {
  25. :>               int number;
  26. :>               struct boxes *pointer_1;
  27. :>               struct boxes *pointer_2;
  28. :>               struct boxes *pointer_3;
  29. :>              }
  30.  
  31. :> /* ARRAY OF POINTERS TO BOXES STRUCTURE FOR MANAGE */
  32. :> /* SOME BRANCHES OF THE TREE                       */
  33.  
  34. :> struct boxes array_pointers [15];
  35.  
  36. : Should be "struct boxes *array_pointers [15];" otherwise you are defining
  37. : an array of structures.
  38.  
  39. : [snip]
  40.  
  41. : To set "number" in the structure pointed to by array element 3 to 13 you
  42. : would :-
  43.  
  44. :       *array_pointers [3]->number = 13;
  45.  
  46. : To set "pointer_1" in the structure pointed to be array element 3 to
  47. : that pointed to by array element 4 you would :-
  48.  
  49. :       *array_pointers [3]->pointer_1 = array_pointers [4]; 
  50.  
  51. The '*' is incorrect in these two assignments and the compiler would probably
  52. complain about these statements.
  53. The '->' operator dereferences the pointer for you.
  54.  
  55.    array_pointers[3]->pointer_1 = array_pointers[4];
  56.  
  57. is sufficient.
  58.  
  59. Regards
  60.  
  61.    -A.
  62. -- 
  63. | A.Champion                |
  64.